//
//  HNSH_ChatSingleNavView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/27.
//

#import "HNSH_ChatSingleNavView.h"

@interface HNSH_ChatSingleNavView ()
/** 返回按钮 */
@property (nonatomic, strong)UIButton * backBtn;
/* headerImgV */
//@property (nonatomic, strong) UIImageView *headerImgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/**  */
@property (nonatomic, strong)UIButton * searchBtn;
@end

@implementation HNSH_ChatSingleNavView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appWhiteLabelColor];
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor appWhiteLabelColor];
    [self addSubview:self.backBtn];
//    [self addSubview:self.headerImgV];
    [self addSubview:self.nameLabel];
    [self addSubview:self.searchBtn];
}

- (void)addAllLayout{
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(4);
        make.width.mas_equalTo(31);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
    }];
//    [self.headerImgV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(35);
//        make.width.mas_equalTo(40);
//        make.height.mas_equalTo(40);
//        make.top.mas_equalTo(kStatusBarHeight+2);
//    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(40);
        make.top.mas_equalTo(kStatusBarHeight+2);
    }];
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(44);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
    }];
}

//MARK: Myself Methods
- (void)backBtnAction{
    if (self.backBlock) {
        self.backBlock();
    }
}

- (void)searchBtnAction{
    if (self.reportBlock) {
        self.reportBlock();
    }
}

#pragma mark - Setter Methods
- (void)setTitle:(NSString *)title{
    _title = title;
    
    self.nameLabel.text = title;
}

- (void)setImageString:(NSString *)imageString {
    _imageString = imageString;
//    [self.headerImgV sd_setImageWithURL:[NSURL URLWithString:imageString] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
}

- (void)setIsHiddenBtn:(BOOL)isHiddenBtn{
    _isHiddenBtn = isHiddenBtn;
    
    self.searchBtn.hidden = isHiddenBtn;
}

#pragma mark - Getter Methods
- (UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"base_nav_back_black"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

//- (UIImageView *)headerImgV {
//    if (!_headerImgV) {
//        _headerImgV = [[UIImageView alloc]init];
//    }
//    return _headerImgV;
//}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"";
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
    }
    return _nameLabel;
}

- (UIButton *)searchBtn{
    if (!_searchBtn) {
        _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchBtn setImage:[UIImage imageNamed:@"base_nav_more"] forState:UIControlStateNormal];
        [_searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
